package com.frogs.ucenter.v1.service.impl.aop;

import javax.annotation.Resource;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.frogs.api.wechat.util.SendMessageUtil;
import com.frogs.system.util.OpenPlatformEnum;
import com.frogs.system.web.api.response.Response;
import com.frogs.ucenter.component.RequestApiHelper;
import com.frogs.ucenter.v1.request.SeedPayRequest;
import com.frogs.ucenter.v1.util.ApiConstants;

@Aspect
@Service(ApiConstants.VERSION+"seedUserAopImpl")
public class SeedUserAopImpl {
	
	private static final Logger log = LoggerFactory.getLogger(SeedUserAopImpl.class);

	@Resource(name = ApiConstants.VERSION + "baseTaskAop")
	private BaseTaskAop baseTaskAop;
	
	@Resource
	private RequestApiHelper requestApiHelper;
	
	@AfterReturning(pointcut="execution(* com.frogs.ucenter.v1.service.impl.SeedUserInfoServiceImpl.addSeedPay(..))",returning="result")
	public void doAfterReturning(JoinPoint jp, Response result)
	{
		try {
			SeedPayRequest sdreq = (SeedPayRequest) jp.getArgs()[0];
			int openPlatformId = OpenPlatformEnum.WECHAT_HDC.getId();
			String accessToken = requestApiHelper.getAccessToken(openPlatformId);
			SendMessageUtil.sendCustomMessage(accessToken, sdreq.getOpenId(), "恭喜您成为蛙鸣健康的种子用户，您的设备会在3~5个工作日寄送给您，感谢您的参与。如有疑问，请联系:400-036-1566");
		} catch (Exception e) {
			log.error("func[SeedUserAopImpl.doAfterReturning] jp[" + jp + "] result[" + result + "] error[" + e.getMessage() + "]", e);
		}
	}
}
